//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.jeecg.chat.service.impl;

import com.jeecg.chat.dao.ImDao;
import com.jeecg.chat.entity.P3ImTSBaseUser;
import com.jeecg.chat.entity.P3ImTSDepart;
import com.jeecg.chat.service.ImService;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.jeecgframework.minidao.annotation.Param;
import org.jeecgframework.minidao.aop.MiniDaoHandler;
import org.jeecgframework.p3.core.utils.common.ApplicationContextUtil;
import org.jeecgframework.p3.core.utils.common.StringUtils;
import org.springframework.stereotype.Service;

@Service("imService")
public class ImServiceImpl implements ImService {
    private Logger log = Logger.getLogger(ImServiceImpl.class);
    @Resource
    private ImDao imDao;

    public ImServiceImpl() {
    }

    public List<P3ImTSBaseUser> getUsers() {
        Object imTSUsers = new ArrayList();

        try {
            MiniDaoHandler minidaoConfig = (MiniDaoHandler)ApplicationContextUtil.getContext().getBean(MiniDaoHandler.class);
            if ("sqlserver".equals(minidaoConfig.getDbType())) {
                imTSUsers = this.getUsersSqlServer();
            } else {
                imTSUsers = this.getUsersOrcl();
            }
        } catch (Exception var3) {
            this.log.error("数据库不兼容:" + var3.toString());
        }

        return (List)imTSUsers;
    }
    
    public List<P3ImTSBaseUser> getUsersClient(String[] lastUsersIds) {
        Object imTSUsers = new ArrayList();

        try {
            MiniDaoHandler minidaoConfig = (MiniDaoHandler)ApplicationContextUtil.getContext().getBean(MiniDaoHandler.class);
            
            imTSUsers = this.imDao.getUsersClient(lastUsersIds);
        } catch (Exception var3) {
            this.log.error("数据库不兼容:" + var3.toString());
        }

        return (List)imTSUsers;
    }

    public List<P3ImTSDepart> getDeparts() {
        return this.imDao.getDeparts();
    }
    
    public List<P3ImTSDepart> getTradersClient() {
        return this.imDao.getTradersClient();
    }
    
    public List<String> getLastMsgUsers(String userid) {
    	return this.imDao.getLastMsgUsers(userid);
    }

    public boolean isInThisOrg(String deptid, String oid) {
    	
    	P3ImTSDepart depart = this.imDao.getDepart(deptid);

    	if (depart == null) {
    		return false;
    	}
    	
        String orgcode = this.imDao.getDepart(deptid).getOrgCode();
        
        if (StringUtils.isNotEmpty(orgcode)) {
        	return orgcode.substring(0, 3).equals(oid);
        } else {
        	return false;
        }
    }

    public int updateSign(String sign, String uid) {
        return this.imDao.update(sign, uid);
    }

    public List<P3ImTSBaseUser> getUsersSqlServer() {
        return this.imDao.getUsersSqlServer();
    }

    public List<P3ImTSBaseUser> getUsersOrcl() throws Exception {
        return this.imDao.getUsers();
    }
}
